package com.ming.handler;

import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;

/**
 * 当订阅的主题有消息时就会触发此处回调
 */
@Component
public class ReceiverMessageHandler implements MessageHandler {
    @Override
    public void handleMessage(Message<?> message) throws MessagingException {
        Object payload = message.getPayload();  // 获取消息的内容
        System.out.println(message.getHeaders().get("mqtt_receivedTopic"));  // 主题名称
        System.out.println(payload);  // 消息主体
    }
}
